package com.example.accessibilityhelper

import android.content.Context
import android.os.Handler
import android.os.Looper
import android.util.Log
import android.widget.Toast

object ToastUtil {
    private const val TAG = "ToastUtil"
    private lateinit var context:Context

    fun init(context:Context){
        this.context = context
    }

    fun toast(message:String){
        if (Looper.getMainLooper() != Looper.myLooper()){
            Handler(Looper.getMainLooper()).post {
                toastInternal(message)
            }
        }else{
            toastInternal(message)
        }
    }

    private fun toastInternal(message: String){
        Log.i(TAG, "toastInternal: $message")
        Toast.makeText(context,message,Toast.LENGTH_SHORT).show()
    }
}